//
//  LGPatientCardCell.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/3/23.
//  患者卡片

#import "LGPatientCardCell.h"

@interface LGPatientCardCell()

/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)CAGradientLayer *gradientLayer;
/**   */
@property (nonatomic , strong)UILabel *patientName;
/**   */
@property (nonatomic , strong)UILabel *ageLabel;
/**   */
@property (nonatomic , strong)UIView *lineView;
/**   */
@property (nonatomic , strong)UIButton *titleBtn;
/**   */
@property (nonatomic , strong)UILabel *contentLabel;
/**   */
@property (nonatomic , strong)UIButton *patientBtn;
/**   */
@property (nonatomic , copy)NSString *patientId;
@end

@implementation LGPatientCardCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubView];
      
    }
    return  self;
}

-(void)fillWithData:(LGCustomCellData *)data{
    [super fillWithData:data];
    NSDictionary *patientDic = data.customDic[@"msgcontent_doctor"];
    self.patientId = LGNSString(data.customDic[@"bus_id"]);
    self.patientName.text = LGNSString(patientDic[@"name"]);
    NSString *ageStr = [NSString stringWithFormat:@"%@ %@岁",patientDic[@"gender"],patientDic[@"age"]];
    self.ageLabel.text = ageStr;
    [self.ageLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@(16+[ageStr textWidthWithFont:LGFont(14) maxHeight:MAXFLOAT]));
    }];
    self.contentLabel.text = [patientDic[@"content"] length]>0?patientDic[@"content"]:@"";
    if([patientDic[@"gender"] isEqualToString:@"男"]){
        self.ageLabel.textColor = [UIColor colorWithString:@"#2E9AFC"];
        self.ageLabel.backgroundColor = [UIColor colorWithString:@"#BADEFF"];
    }else{
        self.ageLabel.textColor = [UIColor colorWithString:@"#E3516B"];
        self.ageLabel.backgroundColor = [UIColor colorWithString:@"#FFDAE0"];
    }
}


-(void)patientBtnAction{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"CheckDiseaseOverview" object:nil userInfo:@{@"patientId":self.patientId}];
}



-(void)layoutSubviews{
    [super layoutSubviews];
    CGFloat height = self.container.size.height;
    self.baseView.frame = CGRectMake(0, 0, Screen_W-viewPix(100), height);
    self.gradientLayer.frame = CGRectMake(0, 0, Screen_W-viewPix(100), height);
}

-(void)createSubView{
//    [self.baseView.layer addSublayer:self.gradientLayer];
    [self.container addSubview:self.baseView];
    [self.baseView addSubview:self.patientName];
    [self.baseView addSubview:self.ageLabel];
    [self.baseView addSubview:self.lineView];
    [self.baseView addSubview:self.titleBtn];
    [self.baseView addSubview:self.contentLabel];
    [self.baseView addSubview:self.patientBtn];
    [self.patientName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.baseView).offset(viewPix(12));
        make.top.equalTo(self.baseView).offset(viewPix(10));
        make.height.equalTo(@(viewPix(20)));
    }];
    [self.ageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.patientName.mas_right).offset(viewPix(10));
        make.centerY.equalTo(self.patientName);
        make.width.equalTo(@(65));
        make.height.equalTo(@(viewPix(20)));
    }];
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.baseView).offset(viewPix(12));
        make.top.equalTo(self.baseView).offset(viewPix(75));
        make.right.equalTo(self.baseView).offset(-viewPix(10));
    }];
    [self.patientBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.baseView).offset(viewPix(16));
        make.right.equalTo(self.baseView).offset(-viewPix(16));
        make.top.equalTo(self.contentLabel.mas_bottom).offset(viewPix(15));
        make.height.equalTo(@(viewPix(30)));
    }];
}

-(UIView *)baseView{
    if(!_baseView){
        _baseView = [[UIView alloc] init];
        _baseView.backgroundColor = [UIColor whiteColor];
        _baseView.cornerRidus = 10;
    }
    return _baseView;
}

-(CAGradientLayer *)gradientLayer{
    if(!_gradientLayer){
        _gradientLayer = [[CAGradientLayer alloc]init];
        _gradientLayer.startPoint = CGPointMake(0.5, 0);
        _gradientLayer.endPoint = CGPointMake(0.5, 1);
        _gradientLayer.colors = @[(__bridge id)[UIColor colorWithString:@"#E4F2FF"].CGColor, (__bridge id)[UIColor colorWithString:@"#FFFFFF"].CGColor];
        _gradientLayer.locations = @[@(0), @(1.0f)];
    }
    return _gradientLayer;
}

-(UILabel *)patientName{
    if(!_patientName){
        _patientName = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFontWeight(14, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _patientName;
}

-(UILabel *)ageLabel{
    if(!_ageLabel){
        _ageLabel = [UILabel lableWithText:@"" colorString:@"#2E9AFC" textFont:LGFont(12) textAlignment:NSTextAlignmentCenter lines:1];
        _ageLabel.backgroundColor = [UIColor colorWithString:@"#BADEFF"];
        _ageLabel.cornerRidus = viewPix(10);
    }
    return _ageLabel;
}

-(UIView *)lineView{
    if(!_lineView){
        _lineView = [[UIView alloc] initWithFrame:CGRectMake(viewPix(12), viewPix(40), Screen_W-viewPix(124), 0.5)];
        _lineView.backgroundColor = [UIColor colorWithString:@"#E0E0E0"];
    }
    return _lineView;
}


-(UIButton *)titleBtn{
    if(!_titleBtn){
        _titleBtn = [UIButton buttonWithTitle:@"病情描述" titleFont:LGFont(14) textColor:@"#666666" imageName:@"患者档案-病情描述"];
        _titleBtn.frame = CGRectMake(viewPix(12), viewPix(50), viewPix(90), viewPix(22));
        _titleBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        _titleBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 6, 0, 0);
    }
    return _titleBtn;
}

-(UILabel *)contentLabel{
    if(!_contentLabel){
        _contentLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFont(12) textAlignment:NSTextAlignmentLeft lines:0];
    }
    return _contentLabel;
}


-(UIButton *)patientBtn{
    if(!_patientBtn){
        _patientBtn = [UIButton buttonWithTitle:@"查看患者详情" titleFont:LGFontWeight(14, UIFontWeightMedium) textColor:@"#3291FF" imageName:@""];
        _patientBtn.layer.borderColor = [UIColor colorWithString:@"#CCE4FF"].CGColor;
        _patientBtn.layer.borderWidth = 1;
        _patientBtn.cornerRidus = viewPix(15);
        [_patientBtn addTarget:self action:@selector(patientBtnAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _patientBtn;
}



- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
